package swing;

import app.Main;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.text.SimpleDateFormat;
import java.util.Date;

import static app.Main.viewChange;

public class MainView extends JPanel{
    public JPanel JPanel0;
    private JLabel Title;
    private JPanel JPanel1;
    private JPanel JPanel2;
    private JButton Button1;
    private JButton Button2;
    private JButton Button3;

    public MainView() {
        Font font = new Font("楷体", Font.BOLD,40);
        Title.setFont(font);
        font = new Font("楷体", Font.BOLD,20);
        Button1.setFont(font);
        Button2.setFont(font);
        Button3.setFont(font);
//        Color color = new Color(0xff, 0xf5, 0xee);
        Color color = new Color(0xf7, 0xf7, 0xf7);
        Button1.setBackground(color);
        Button2.setBackground(color);
        Button3.setBackground(color);

        JPanel0.setOpaque(false);
        JPanel1.setOpaque(false);
        JPanel2.setOpaque(false);


        Button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                viewChange = 1;
                synchronized (Main.object){
                    Main.object.notify();
                }
            }
        });
        Button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null, "确认退出?", "确认",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
                if (result == JOptionPane.OK_OPTION) {
                    // 退出
                    System.exit(0);
                }
            }
        });

        Button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                viewChange = 2;
                synchronized (Main.object){
                    Main.object.notify();
                }
            }
        });
    }

    private static void copyFileUsingFileChannels(File source, File dest) throws IOException {
        FileChannel inputChannel = null;
        FileChannel outputChannel = null;
        try {
            inputChannel = new FileInputStream(source).getChannel();
            outputChannel = new FileOutputStream(dest).getChannel();
            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
        } finally {
            inputChannel.close();
            outputChannel.close();
        }
    }
}
